package com.milhouz.findmydroid;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

import com.milhouz.findmydroid.db.AppConstants;
import com.milhouz.findmydroid.db.AppProvider;
import com.milhouz.findmydroid.db.DbLoaderASyncTask;

public class SplashScreenActivity extends Activity {

	private static final int SPLASH_SCREEN_DURATION = 3000;

	private final static Handler mUiThreadCallback = new Handler();
	private Context mContext;

	/** Execute MainMenuActivity after loading */
	private final Runnable mRunAfterLoading = new Runnable() {
		@Override
		public void run() {
			Intent intent = new Intent(mContext, MainMenuActivity.class);
			startActivity(intent);
			finish();
		}
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Set the fullscreen mode
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setContentView(R.layout.splash_screen);
		mContext = this.getApplicationContext();

		// Splash screen temporisé
		mUiThreadCallback.postDelayed(mRunAfterLoading, SPLASH_SCREEN_DURATION);

		getContentResolver().delete(AppProvider.CATEGORIES_URI, null, null);
		getContentResolver().delete(AppProvider.CHARACTERS_URI, null, null);
		Log.i(AppConstants.TAG, "Execute data loader in ASyncTask");
		DbLoaderASyncTask asyncTask = new DbLoaderASyncTask(getApplicationContext());
		asyncTask.execute(0);

	}

}
